// pages/releaseComment/releaseComment.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex:'',
    pageContent:'',
    pageTotal:'',
    releaseTime:'',
    userComm:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取用户书评
    this.setData({
      pageIndex:1,
      pageContent:4
    })
    this.getUserComment()
  },
  getUserComment(){
    wx.request({
      url: 'http://124.222.95.170:21311/discuss/myDiscuss',
      method:'GET',
      header: {
        'Cookie': wx.getStorageSync('sessionid')
      },
      data:{
        "page":this.data.pageIndex,
        "pageSize":this.data.pageContent
      },
      success:(res)=>{
        if(res.data.msg == 'NOTLOGIN'){
          wx.showToast({
            title: '登陆后才能使用该功能哦',
            icon:'none'
          })
          setTimeout(function() {
            // 1.3s后返回
            wx.switchTab({
              url: '/pages/users/users',
              success: function(res) {
                console.log('未登录，返回到个人页面')
              },
              fail: function(res) {},
              complete: function(res) {},
            })
          }, 1300);
        }else{
          let arr = res.data.data
          this.setData({
            userComm:this.data.userComm.concat(arr.records),
            pageTotal:arr.total
          })
        }
        
      }
    })
  },
  goDetail(item){
    var res = item.currentTarget.dataset.item
      wx.navigateTo({
        url: '/pages/commentDetails/commentDetails?content='+ res.discuss.content + '&createTime='+res.discuss.createTime + '&id='+ res.discuss.id + '&title=' + res.discuss.title + '&userId=' + res.discuss.userId + '&views=' + res.discuss.views + '&avatarUrl=' + res.user.avatarUrl + '&nickName=' + res.user.nickName + '&isShow=' + true,
      })
  },
  gotoRelease(){
    wx.switchTab({
      url: '/pages/community/community',
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.pageIndex * this.data.pageContent >= this.data.pageTotal){
      wx.showToast({
        title: '已经到底了',
        icon:'none'
      })
      return;
    }
    this.data.pageIndex++
    this.getUserComment()
  },  
})